require.config({
	paths:{
		'jquery':'jquery'
	}
})
require(['jquery'],function($){
	//创建cookie函数
	function createCookie(key,value,expires){
		var cookieText = encodeURIComponent(key) + "=" + encodeURIComponent(value) + ";path:/";		
		//有效期
		if(expires && typeof expires == "number" && expires > 0){
			var date = new Date();
			date.setDate(date.getDate() + expires);
			cookieText += ";expires= " + date;
		}
		document.cookie = cookieText;
	}
	//获取cookie
	function gainCookie(key){
		var arr = document.cookie.split("; ");
		for(var i = 0;i < arr.length;i ++){
			var list = arr[i].split("=");
			if(encodeURIComponent(key) == list[0]){
				return decodeURIComponent(list[1]);
				break;
			}
		}
	}
	//清除cookie
	function removeCookie(key){
		document.cookie = encodeURIComponent(key) + "=;expires=" + new Date(0) + ";path=/";
	}
	//自动登录
	//判断是否为第一次登录
	if(gainCookie("用户") && gainCookie("密码")){
		$('.enter .enter1 .entermessage .users').val(gainCookie("用户"))
		$('.enter .enter1 .entermessage .password').val(gainCookie("密码"))
	}
	//点击自动登录时创建cookie
	$('.enter .enter1 .entermessage .logoin .check').click(function(){
		createCookie("用户",$('.enter .enter1 .entermessage .users').val(),7);
		createCookie("密码",$('.enter .enter1 .entermessage .password').val(),7);
	})
	//点击登录按钮
	$('.enter .enter1 .entermessage .lastenter').click(function(){
		if($('.enter .enter1 .entermessage .users').val() == '' || $('.enter .enter1 .entermessage .password').val() == ''){
			alert("请输入用户或密码!!!");
		}
		if($('.code').val() == ''){
			alert("请输入验证码!!!");
		}
		if($('.code').val() != $('.codebox').html().toLowerCase() && $('.code').val() != $('.codebox').html().toUpperCase()){
			alert("请输入正确的验证码!!!")
		}
		else{
			location.href = '../index.html';
		}
	})
	//验证码
	var code = '';
	var str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	$('.codebox').click(function(){
		creatCode();
	})
	function creatCode(){
		for(var i = 1;i < 5;i ++){
			var num = Math.floor(Math.random()*62);
			code += str.charAt(num);
		}
		$('.codebox').html(code);
		code = '';
	}
	creatCode();
})